package com.lucy.nepu.utils;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ArrayUtil;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author kindear
 * 表单校验器
 */
@Component
public class ValidUtil {
    public static String formValid(Object dto){
        Map<String,Object> map = BeanUtil.beanToMap(dto);
        // 表单重复性校验
        String errMsg = "";
        Long operator = StpUtil.getLoginIdAsLong();
        Long leaderId = (Long) map.get("leaderId");
        if (!leaderId.equals(operator)){
            errMsg = "您不是负责人，无法申报该项目";
            return errMsg;
        }
        List<Long> userIds = (List<Long>) map.get("userIdList");
        if (userIds.contains(leaderId)){
            errMsg = "参与人员中不需添加负责人";
            return errMsg;
        }
        return errMsg;
    }
}
